<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/3
 * Time: 15:33
 */
namespace common\logics\member;

use common\widgets\Tool;
use yii\base\BaseObject;
use Yii;

class MemberLogic extends BaseObject implements IMember
{
    /*** @var \common\sources\read\member\MemberAccess $RMemberAccess */
    private $RMemberAccess;
    /** @var \common\sources\read\taobao\TaoBaoAccess $RTaoBaoAccess **/
    private $RTaoBaoAccess;
    /** @var \common\sources\write\taobao\TaoBaoAccess $WTaoBaoAccess **/
    private $WTaoBaoAccess;
    /** @var \common\sources\read\bank\BankAccess $RBankAccess **/
    private $RBankAccess;
    /** @var \common\sources\write\bank\BankAccess $WBankAccess **/
    private $WBankAccess;
    /** @var \common\sources\read\buyuser\BuyUserAccess $RBuyUserAccess **/
    private $RBuyUserAccess;
    /** @var \common\sources\write\buyuser\BuyUserAccess $WBuyUserAccess **/
    private $WBuyUserAccess;
    /*** @var \common\sources\read\shop\ShopAccess $RShopAccess */
    private $RShopAccess;
    /** @var \common\sources\write\shop\ShopAccess $WShopAccess **/
    private $WShopAccess;
    /** @var \common\sources\read\sendddcode\SendDdCodeAccess $RSendDdCodeAccess **/
    private $RSendDdCodeAccess;
    /** @var \common\sources\write\sendddcode\SendDdCodeAccess $WSendDdCodeAccess **/
    private $WSendDdCodeAccess;
    /** @var \common\sources\read\taskorder\TaskOrderAccess $RTaskOrderAccess **/
    private $RTaskOrderAccess;
    /** @var \common\sources\write\expiretimelog\ExpireTimeLogAccess $WExpireTimeLogAccess **/
    private $WExpireTimeLogAccess;
    /** @var \common\sources\read\expiretimelog\ExpireTimeLogAccess $RExpireTimeLogAccess **/
    private $RExpireTimeLogAccess;
    /** @var \common\sources\read\classifyreason\ClassifyReasonAccess $RClassifyReasonAccess **/
    private $RClassifyReasonAccess;
	/** @var \common\sources\read\taskcommod\TaskCommodAccess $RTaskCommodAccess **/
    private $RTaskCommodAccess;

    public function init()
    {
        $this->RMemberAccess = Yii::$container->get("RMemberAccess");
        $this->RTaoBaoAccess = Yii::$container->get("RTaoBaoAccess");
        $this->WTaoBaoAccess = Yii::$container->get("WTaoBaoAccess");
        $this->RBankAccess = Yii::$container->get("RBankAccess");
        $this->WBankAccess = Yii::$container->get("WBankAccess");
        $this->RBuyUserAccess = Yii::$container->get("RBuyUserAccess");
        $this->WBuyUserAccess = Yii::$container->get("WBuyUserAccess");
        $this->RShopAccess = Yii::$container->get("RShopAccess");
        $this->WShopAccess = Yii::$container->get("WShopAccess");
        $this->RSendDdCodeAccess = Yii::$container->get("RSendDdCodeAccess");
        $this->WSendDdCodeAccess = Yii::$container->get("WSendDdCodeAccess");
        $this->RTaskOrderAccess = Yii::$container->get("RTaskOrderAccess");
        $this->WExpireTimeLogAccess = Yii::$container->get("WExpireTimeLogAccess");
        $this->RExpireTimeLogAccess = Yii::$container->get("RExpireTimeLogAccess");
        $this->RClassifyReasonAccess = Yii::$container->get("RClassifyReasonAccess");
        $this->RTaskCommodAccess = Yii::$container->get("RTaskCommodAccess");
        parent::init(); // TODO: Change the autogenerated stub
    }

    //list
    public function getList($data)
    {
        if(empty($data['role'])){
            return Tool::returnJson([],401,"用户角色不能为空");
        }

        //对应买号
	    if (($data['search_type'] == 5) && $data['name']) {
		    $taobaoInfo   = $this->RTaoBaoAccess->getTaoBaoByTbname($data['name']);
		    $data['name'] = 0;
		    if ($taobaoInfo) {
			    $data['name'] = $taobaoInfo['buy_id'];
		    }
	    }

        $result = $this->RMemberAccess->getList($data);
        $count = $this->RMemberAccess->getList($data,true);
        if($count <$data['limit'])
        {
            $data['page'] =1;
        }

        if(count($result)>0){
            foreach ($result as &$item){
                $item['reg_time'] = isset($item['reg_time']) ? date('Y-m-d H:i:s',$item['reg_time']):'';
                $item['expire_time'] = isset($item['expire_time']) ? date('Y-m-d H:i:s',$item['expire_time']):'';
                $item['send_receive_time'] = isset($item['send_receive_time']) ? date('Y-m-d H:i:s',$item['send_receive_time']):'';
                $item['login_time'] = isset($item['login_time']) ? date('Y-m-d H:i:s',$item['login_time']):'';
	            if (isset($item['pid'])) {
		            $pInfo = $this->RMemberAccess->getUserInfo($item['pid']);
		            if ($pInfo) {
			            $item['pid'] = $pInfo['phone'];
		            } else {
			            $item['pid'] = '';
		            }
	            }
            }
	        unset($item);
        }

        return Tool::returnJson([
            'list' => $result,
            'page' => $data['page'],
            'count' => $count,
        ],200,'成功');
    }
    //会员显示隐藏
    public function getDisplay($data)
    {
        if(empty($data['buy_id'])){
            return Tool::returnJson([],401,"买手用户或者商家用户id不能为空");
        }
        if(empty($data['role'])){
            return Tool::returnJson([],402,"买手或者商户角色不能为空");
        }
        if(empty($data['o_id'])){
            return Tool::returnJson([],403,"绑定淘宝id 或者绑定店铺id不能为空");
        }
        if(!isset($data['display'])){
            return Tool::returnJson([],405,"显示隐藏参数有误");
        }
        if(!($data['role'] == 1 || $data['role'] == 2)){
            return Tool::returnJson([],407,"用户角色有误");
        }
        $buyer = $this->RBuyUserAccess->getBuyUserInfo($data['buy_id']);
        if(empty($buyer)){
            return Tool::returnJson([],409,"买手或者商家号不存在");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        //删除钉钉验证码
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);

        $res = false;
        if($data['role'] == 1 ){ //买手=》买号
        	//检测任务
	        $orderCount = $this->RTaskOrderAccess->getBuyOrderCounts('buy_id=:buy_id and (order_status != 10 or order_status != 11)', [':buy_id' => $data['buy_id']]);
	        if ($orderCount != 0) {
		        return Tool::returnJson($data = [], $code = 401, '买号不可隐藏');
	        }

           $res = $this->WTaoBaoAccess->display($data);
        }else if($data['role'] == 2 ){//商家=》店铺
	        //检测任务
	        $count = $this->RTaskCommodAccess->getShopTaskCount(['bus_id' => $data['buy_id']]);
	        if ($count != 0) {
		        return Tool::returnJson($data = [], $code = 401, '店铺不可隐藏');
	        }
            $res = $this->WShopAccess->modifyShop($data);
        }
        if($res){
            return Tool::returnJson([],200,"成功");
        }
        return Tool::returnJson([],408,"操作失败");

    }
    //修改可接任务数
    public function modifyAccessTask($data)
    {
        if(empty($data['t_id'])){
            return Tool::returnJson([],401,"绑定淘宝id 或者绑定店铺id不能为空");
        }
        //根据id 获取淘宝或者天猫信息
        $taobao = $this->RTaoBaoAccess->getTaoBaoByTid($data['t_id']);
        if(empty($taobao)){
            return Tool::returnJson([],512,"绑定淘宝或者天猫账号不存在");
        }
        if (!isset($data['num'])) {
            return Tool::returnJson([],401,"请传可接任务数");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);        //删除钉钉验证码
        $result = $this->WTaoBaoAccess->modifyAccessTaskNum($data['t_id'],$data['num']);
        if($result){
            return Tool::returnJson([],200,"修改成功");
        }
        return Tool::returnJson([],511,"修改可接任务数失败");
    }
    //修改买号性别
    public function modifySex($data)
    {
        if(empty($data['buy_id'])){
            return Tool::returnJson([],401,"买手用户id不能为空");
        }
        if(empty($data['o_id'])){
            return Tool::returnJson([],402,"买号绑定id不能为空");
        }
        if(empty($data['sex'])){
            return Tool::returnJson([],403,"性别不能为空");
        }
        $buyer = $this->RBuyUserAccess->getBuyUserInfo($data['buy_id']);
        if(empty($buyer)){
            return Tool::returnJson([],409,"买手或者商家号不存在");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        //删除钉钉验证码
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);
        //修改买号性别
        $modifySex = $this->WTaoBaoAccess->modifySex($data);
        if (!$modifySex) {
            return Tool::returnJson([],200,"修改失败");
        }
        return Tool::returnJson([],200,"修改成功");
    }


    //获取买手或者商家
    public function getBuyers($param)
    {
        if(empty($param['b_id'])){
            return Tool::returnJson([],401,"会员id不能为空");
        }
        if(empty($param['role'])){
            return Tool::returnJson([],402,"会员角色不能为空");
        }
        $data = [];
        if($param['role'] == 1){
            //获取绑定买号
            $result = $this->RTaoBaoAccess->getTaoBaoById($param['b_id']);
//            if ($result) {
//                for
//            }
            $data['buyers'] = $result;
        }else if($param['role'] == 2 ){
            $result = $this->RShopAccess->getShop($param['b_id']);
            $data['buyers'] = $result;
        }
        //获取绑定提现信息
        $bank = $this->RBankAccess->getBankMessage($param['b_id']);
        $data['bank'] = $bank;

        return Tool::returnJson($data,200,"成功");

    }
    //修改手机
    public function modifyPhone($param)
    {
        if(empty($param['buy_id'])){
            return Tool::returnJson([],401,"用户id不能为空");
        }
        if(empty($param['old_phone'])){
            return Tool::returnJson([],402,"旧手机号码不能为空");
        }
        if(empty($param['new_phone'])){
            return Tool::returnJson([],403,"新手机号码不能为空");
        }
        if(empty($param['confirm_phone'])){
            return Tool::returnJson([],405,"确认手机号码不能为空");
        }
        if($param['new_phone'] != $param['confirm_phone']){
            return Tool::returnJson([],406,"新手机号码与确认手机号码不一致");
        }
        if($param['old_phone'] == $param['new_phone']){
            return Tool::returnJson([],407,"新手机与原手机一致");
        }
        //查看旧手机是否存在
        $buyer = $this->RBuyUserAccess->getBuyUserInfo($param['buy_id']);
        if(empty($buyer)){
            return Tool::returnJson([],408,"会员不存在");
        }
        //验证会员id对应 与旧手机号码
        if($param['old_phone'] != $buyer['phone']){
            return Tool::returnJson([],409,"旧手机与对应的账号手机不符");
        }
        //检查新手机是否存在
        $new_buyers = $this->RBuyUserAccess->getBuyUserByPhone($param['new_phone']);
        if(!empty($new_buyers)){
            return Tool::returnJson([],510,"该新号码已经存在,请重新输入");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);        //删除钉钉验证码
        //修改手机号码
        $result = $this->WBuyUserAccess->modifyPhone($param['buy_id'], $param['new_phone']);
        if($result){
            return Tool::returnJson([],200,"修改成功");
        }
        return Tool::returnJson([],511,"修改手机号码失败");
    }
    //修改买手会员名称
    public function modifyTbName($data)
    {
        if(empty($data['t_id'])){
            return Tool::returnJson([],401,"会员账号id不能为空");
        }
        if(empty($data['tbname'])){
            return Tool::returnJson([],402,"会员名称不能为空");
        }
        //获取买号会员信息
        $buyers = $this->RTaoBaoAccess->getTaoBaoByTid($data['t_id']);
        if(empty($buyers)){
            return Tool::returnJson([],405, "买号会员信息不存在");
        }
        //新的会员名称与原来的会员名称是否一致
        if( $buyers['tbname']  == $data['tbname']){
            return Tool::returnJson([],406,"新会员名称与原会员名称一致");
        }
        $tbname = $this->RTaoBaoAccess->getTaoBaoByTbname($data['tbname']);
        if ($tbname) {
            return Tool::returnJson([],406,"该买号名已存在，请重新修改");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);        //删除钉钉验证码

        //修改会员名称
        $result = $this->WTaoBaoAccess->modifyTbName($data);
        if($result){
            return Tool::returnJson([],200,"成功");
        }
        return Tool::returnJson([],407,"修改会员名称失败");
    }
    //删除买号
    public function delMember($data)
    {
        if(empty($data['t_id'])){
            return Tool::returnJson([],401,"会员账号id不能为空");
        }
        //获取买号会员信息
        $tbUser = $this->RTaoBaoAccess->getTaoBaoByTid($data['t_id']);
        if(empty($tbUser)){
            return Tool::returnJson([],405, "买号会员信息不存在");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);        //删除钉钉验证码
        //检查该买号是否已经接单
        $alsoAccessTask = $this->RTaskOrderAccess->checkTask($data['t_id']);
        if ($alsoAccessTask) {
            return Tool::returnJson([],513,"该买号已经接单,不能删除");
        }
        $result = $this->WTaoBaoAccess->delMember($data['t_id']);
        if (!$result) {
            return Tool::returnJson([],513,"删除失败");
        }
        return Tool::returnJson([],200,"删除成功");
    }
    //修改会员地址
    public function modifyAreaAddr($data)
    {
        if(empty($data['t_id'])){
            return Tool::returnJson([],401,"数据id不能为空");
        }
        if(empty($data['takename'])){
            return Tool::returnJson([],402,"收货人不能为空");
        }
        if(empty($data['pro_name'])){
            return Tool::returnJson([],403,"省名称不能为空");
        }
        if(empty($data['pro_code'])){
            return Tool::returnJson([],405,"省代号不能为空");
        }
        if(empty($data['city_name'])){
            return Tool::returnJson([],406,"市名称不能为空");
        }
        if(empty($data['city_code'])){
            return Tool::returnJson([],407,"市代号不能为空");
        }
        if(empty($data['area_name'])){
            return Tool::returnJson([],408,"区名称不能为空");
        }
        if(empty($data['area_code'])){
            return Tool::returnJson([],409,"区代号不能为空");
        }
        if(empty($data['addr'])){
            return Tool::returnJson([],510,"收货详细地址不能为空");
        }
        if(empty($data['takephone'])){
            return Tool::returnJson([],511,"收货手机号不能为空");
        }
        //根据id 获取淘宝或者天猫信息
        $taobao = $this->RTaoBaoAccess->getTaoBaoByTid($data['t_id']);
        if(empty($taobao)){
            return Tool::returnJson([],512,"绑定淘宝或者天猫账号不存在");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);        //删除钉钉验证码

	    //验证手机号是否存在
	    if($this->RTaoBaoAccess->chkPhoneIs($data)){
		    return Tool::returnJson([],401,"手机号已绑定其他收货地址");
	    }

	    //修改收件地址和电话
        $result = $this->WTaoBaoAccess->modifyAreaAddr($data);
        if($result){
            return Tool::returnJson([],200,"修改成功");
        }
        return Tool::returnJson([],513,"修改失败");
    }
    //获取单个会员信息
    public function getSignMember($data) {
        if(empty($data['role'])){
            return Tool::returnJson([],401,"请选择类型");
        }
        if(empty($data['search'])){
            return Tool::returnJson([],401,"请输入搜索条件");
        }
        $result = $this->RMemberAccess->getSignMember($data['role'],$data['search']);
        if (!$result) {
            $result = [];
        }
        if(count($result)>0){
            foreach ($result as &$item){
                $item['reg_time'] = isset($item['reg_time']) ? date('Y-m-d H:i:s',$item['reg_time']):'';
                $item['expire_time'] = isset($item['expire_time']) ? date('Y-m-d H:i:s',$item['expire_time']):'';
                $item['send_receive_time'] = isset($item['send_receive_time']) ? date('Y-m-d H:i:s',$item['send_receive_time']):'';
                $item['login_time'] = isset($item['login_time']) ? date('Y-m-d H:i:s',$item['login_time']):'';
            }
        }
        return Tool::returnJson($result,200,"成功");
    }

    //修改会员过期时间
    public function modifyExpireTime($data) {
        if(empty($data['buy_id'])){
            return Tool::returnJson([],401,"会员账号id不能为空");
        }
        if(empty($data['expire_time'])){
            return Tool::returnJson([],401,"过期时间不能为空");
        }
        if(empty($data['description'])){
            return Tool::returnJson([],401,"备注不能为空");
        }
        if(empty($data['imgUrl'])){
            return Tool::returnJson([],401,"上传截图不能为空");
        }
        if(empty($data['admin_id'])){
            return Tool::returnJson([],401,"操作人id不能为空");
        }
        //增加钉钉验证码=验证
        if(empty($data['sys_code'])){
            return Tool::returnJson([],401,"请填写验证码");
        }
        if(empty($data['phone'])){
            return Tool::returnJson([],401,"操作人手机号不能为空");
        }
        $smsArr = $this->RSendDdCodeAccess->getSendCode($data);
        if (intval($smsArr['code']) !== intval($data['sys_code'])) {
            return Tool::returnJson($data = [], $code = 405, '验证码输入有误');
        }
        $this->WSendDdCodeAccess->delDdCodeById($smsArr['id']);        //删除钉钉验证码
        $buyer = $this->RBuyUserAccess->getBuyUserInfo($data['buy_id']);
        if(empty($buyer)){
            return Tool::returnJson([],409,"买手或者商家号不存在");
        }
        $data['expire_time_befor'] = $buyer['expire_time'];
        $result = $this->RMemberAccess->modifyExpireTime($data);
        if (!$result) {
            return Tool::returnJson([],409,"修改失败");
        }
        //添加修改记录
        $addExpireTimeLog = $this->WExpireTimeLogAccess->addLog($data);
        return Tool::returnJson([],200,"修改成功");
    }

    //获取修改过期时间日志
    public function modifyExpireLog($data){
        if(empty($data['role'])){
            return Tool::returnJson([],401,"类型不能为空");
        }
        if(empty($data['search'])){
            return Tool::returnJson([],401,"搜索手机号不能为空");
        }
        $buyUser = $this->RMemberAccess->getSignMember($data['role'],$data['search']);
        if (!$buyUser) {
            return Tool::returnJson([],200,'用户不存在');
        }
        $result = $this->RExpireTimeLogAccess->modifyExpireLog($buyUser[0]['id'],$data);
        if ($result) {
            foreach ($result as &$value) {
                $value['reg_time'] = date("Y-m-d H:i:s",is_null($buyUser[0]['reg_time']) ? 0 : $buyUser[0]['reg_time']);
                $value['phone'] = $buyUser[0]['phone'];
                $value['role'] = $buyUser[0]['role'];
                $value['expire_time_befor'] = date("Y-m-d H:i:s", $value['expire_time_befor']);
                $value['expire_time_now'] = date("Y-m-d H:i:s", $value['expire_time_now']);
            }
        }
        return Tool::returnJson($result,200,'成功');
    }

    //修改开户名
    public function ModifyBankName($data) {
        if(empty($data['id'])){
            return Tool::returnJson([],401,"用户id不能为空");
        }
        if(empty($data['name'])){
            return Tool::returnJson([],401,"姓名不能为空");
        }
        $result = $this->WBankAccess->ModifyBankName($data);
        if ($result) {
            return Tool::returnJson([],200,'修改成功');
        }
        return Tool::returnJson([],409,'修改失败');
    }

    //用户账户审核
    public function AuditUserBank($data) {
        if(empty($data['id'])){
            return Tool::returnJson([],401,"用户id不能为空");
        }
        if(empty($data['audit_status'])){
            return Tool::returnJson([],401,"审核状态不能为空");
        }
        if(empty($data['operator'])){
            return Tool::returnJson([],401,"操作人不能为空");
        }
        $result = $this->WBankAccess->AuditUserBank($data);
        if ($result) {
            return Tool::returnJson([],200,'成功');
        }
        return Tool::returnJson([],409,'失败');
    }

    //修改银行卡
    public function ModifyBankNum($data) {
        if(empty($data['id'])){
            return Tool::returnJson([],401,"用户id不能为空");
        }
        if(empty($data['cardno'])){
            return Tool::returnJson([],401,"卡号不能为空");
        }
        $exist = $this->WBankAccess->existBank($data);
        if ($exist) {
            return Tool::returnJson([],401,"卡号已存在");
        }
        $result = $this->WBankAccess->ModifyBankNum($data);
        if ($result) {
            return Tool::returnJson([],200,'成功');
        }
        return Tool::returnJson([],409,'失败');
    }

    //会员黑名单列表
    public function UserBlackList($data) {
        $list = $this->RBuyUserAccess->UserBlackList($data);
        $count = $this->RBuyUserAccess->CountUserBlackList($data);
        return Tool::returnJson([
        "list" => $list,
        "page_num" => $data['page_num'],
        "limit" => $data['limit'],
        "count" => $count,
        ],200,"成功");
    }

    //添加黑名单会员
    public function AddBlackUser($data) {
        if(empty($data['userId'])){
            return Tool::returnJson([],401,"用户id不能为空");
        }
        $buyer = $this->RBuyUserAccess->getBuyUserInfo($data['userId']);
        if(empty($buyer)){
            return Tool::returnJson([],409,"买手或者商家号不存在");
        }
        if(empty($data['freeze_status'])){
            return Tool::returnJson([],401,"冻结类型不能为空");
        }
        if(empty($data['freeze_operator'])){
            return Tool::returnJson([],401,"操作人不能为空");
        }
        $result = $this->WBuyUserAccess->AddBlackUser($data);
        if ($result) {
            return Tool::returnJson([],200,'成功');
        }
        return Tool::returnJson([],200,'失败');
    }

    public function UserBankList($data) {
        $list = $this->RBankAccess->UserBankList($data);
        if ($list) {
            foreach ($list as &$value) {
                $value['phone'] = isset($this->RBuyUserAccess->getBuyUserInfo($value['buy_id'])['phone']) ? $this->RBuyUserAccess->getBuyUserInfo($value['buy_id'])['phone'] : '';
                if (!empty($value['reason'])) {
                    $ids = explode(',',$value['reason']);
                    $value['reason'] = $this->RClassifyReasonAccess->getReason($ids);
                }
            }
        }
        return Tool::returnJson($list,200,'成功');
    }

	/**
	 * userExport 导出商家
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/20
	 * @param $data
	 * @return int|string
	 */
	public function userExport($data) {
		$where   = ' 1=1 ';
		$endTime = time() - ($data['day_num'] * 86400);
		if ($data['order_status'] == 4) {
			$where = ' print_time <=' . $endTime;
		}
		$busId = $this->RTaskOrderAccess->getOrderField($where, 'bus_id');

		$data['role'] = 2;
		$data['ids']  = isset($busId) ? implode(',', $busId) : '0';
		$list         = $this->RMemberAccess->newGetList($data);
		if ($list) {
			foreach ($list as &$value) {
				$value['reg_time']    = isset($value['reg_time']) ? date('Y-m-d H:i:s', $value['reg_time']) : '';
				$value['expire_time'] = isset($value['expire_time']) ? date('Y-m-d H:i:s', $value['expire_time']) : '';
				$value['login_time']  = isset($value['login_time']) ? date('Y-m-d H:i:s', $value['login_time']) : '';
				if (isset($value['pid'])) {
					$pInfo = $this->RMemberAccess->getUserInfo($value['pid']);
					if ($pInfo) {
						$value['pid'] = $pInfo['phone'];
					}
				}
			}
			unset($value);
		}
		return Tool::returnJson($list, 200, '成功');
	}
}